<?php

declare(strict_types=1);

namespace App\Mall\Model;

use App\Fastapp\Model\FileTrait;
use Hyperf\Database\Model\Relations\HasMany;
use Hyperf\Database\Model\Relations\HasOne;
use Mine\MineModel;

/**
 * @property int $id 主键
 * @property array $name 规格
 * @property string $image image
 * @property int $is_default 
 * @property int $goods_id goods_id
 * @property int $stock 库存
 * @property int $sells 卖出数
 * @property int $return 退货数
 * @property-read null|MallGoods $goods 
 */
class MallGoodsSpec extends MineModel
{
    use FileTrait;
    public bool $timestamps = false;

    /**
     * The table associated with the model.
     */
    protected ?string $table = 'mall_goods_spec';

    /**
     * The attributes that are mass assignable.
     */
    protected array $fillable = ['id', 'name', 'image', 'is_default', 'goods_id', 'stock', 'sells', 'return'];

    /**
     * The attributes that should be cast to native types.
     */
    protected array $casts = ['id' => 'integer', 'name' => 'array', 'is_default' => 'integer', 'goods_id' => 'integer', 'stock' => 'integer', 'sells' => 'integer', 'return' => 'integer'];

    public function goods(): HasOne
    {
        return $this->hasOne(MallGoods::class, 'id', 'goods_id');
    }

    public function price(): HasMany
    {
        return $this->hasMany(MallGoodsPrice::class, 'spec_id', 'id');
    }
}
